const path = require("path");
const {
    CleanWebpackPlugin
} = require('clean-webpack-plugin');
const webpack = require("webpack");

module.exports = {
    // 设置主目录
    context: path.resolve(__dirname, ".."),

    // 设置入口
    entry: "./src/main.js",

    // 设置输出
    output: {
        filename: "[name].[hash].js",
        path: path.resolve(__dirname, "..", "dist"),
        pathinfo: true,

        publicPath: "/assets/",
        chunkFilename: "[id].chunk.js"
    },

    // 解析
    resolve: {},

    // 模块
    module: {},

    // 插件
    plugins: [
        // new webpack.ProgressPlugin((percentage, message, ...args) => {
        //   // e.g. Output each progress message directly to the console:
        //   console.info(percentage, message, ...args);
        // }),
        new webpack.ProgressPlugin({
            activeModules: false,
            entries: true,
            handler(percentage, message, ...args) {
                console.info(percentage, message, ...args);
            },
            modules: true,
            modulesCount: 5000,
            profile: false,
            dependencies: true,
            dependenciesCount: 10000,
            percentBy: null
        }),

        /**
         * All files inside webpack's output.path directory will be removed once, but the
         * directory itself will not be. If using webpack 4+'s default configuration,
         * everything under <PROJECT_DIR>/dist/ will be removed.
         * Use cleanOnceBeforeBuildPatterns to override this behavior.
         *
         * During rebuilds, all webpack assets that are not used anymore
         * will be removed automatically.
         *
         * See `Options and Defaults` for information
         */
        new CleanWebpackPlugin(),
    ]
};
